<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<title>${aier_title}</title>
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/multiselect.css" />
<link rel="stylesheet" href="${aier_css_url}jc/chosen.css">
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/reset.css" />
<link rel="stylesheet" href="${aier_css_url}social/school/common.css" />
<link rel="stylesheet" href="${aier_css_url}social/school/smanage.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}ui.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/ja.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/multiselect.js"></script>
<script type="text/javascript" src="${aier_js_url}social/school/attend/smica.js"></script>

<script type="text/javascript">
	var global_suffix = "${aier_suffix}", global_url = "${aier_url}", global_uri = "${aier_uri}", global_urijs = "${aier_urijs}", 
		global_sid = "${sid}", global_tid = "${tid}";
</script>
</head>
<body>

	<!-- 顶栏 -->
	<s:action name="userhomecomm_homeHead" namespace="/user"
		executeResult="true"></s:action>

	<!-- 正文 -->
	<div id="hfContent" class="ar-content">
		<div class="content-main">
			<!-- 学校名称栏 -->
			<s:action name="scomm_schoolMTitle" namespace="/school"
				executeResult="true"></s:action>
			<div class="main-content wrap-bg clearfix">
				<!-- 左侧栏 -->
				<s:action name="scomm_schoolMLeft" namespace="/school"
					executeResult="true"></s:action>
				<!-- 右侧内容 -->
				<div class="ae-right">
					<div class="right-main">
						<div class="right-main-top">
							<div class="binfo-title">
								<h3>IC卡管理</h3>
							</div>
							<div class="right-line"></div>
						</div>
						<div class="right-main-c">
						    <div id="tabsCm">
						        <ul>
                                    <li><a href="#tabs-1">ic卡列表</a>
                                    </li>
                                    <li><a href="#tabs-2" onclick="addStudentIc()">学生绑卡</a> 
                                    </li>
                                    <li><a href="#tabs-3" onclick="addTeacherIc()">教师绑卡</a> 
                                    </li>
                                </ul>
                                <div id="tabs-1">
                                
									<div class="info-tab01">
										<table>
											<tbody>
												<tr>
													<th class="gray6" style="text-align: right;">卡号：</th>
													<td style="text-align: left">
														<select id="icard_num" data-placeholder="请选择或输入职务"
															Class="chosen" tabindex="1">
																<option value="">所有卡号</option>
																<c:forEach  var="card" items="${cardNumList }">
																	<option value="${card}">${card}</option>
																</c:forEach>
														</select>
													</td>
												</tr>
												
												<tr>
													<th class="gray6" style="text-align: right">卡状态：</th>
													<td style="text-align: left">
														<select id="card_state_types" class="chosen">
															<option value="-1">请选择</option>
															<option value="10">启用</option>
															<option value="20">注销</option>
														</select>
													</td>
													
													<td colspan="2" align="right"><a
														onclick="search_card()" href="javascript:;"
														class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only fr"
														role="button" aria-disabled="false"><span
															class="ui-button-text">查询</span> </a></td>
												</tr>
											</tbody>
		
										</table>
									</div>
									<div class="right-main-down">
										<div class="down-line"></div>
		
										<div class="down-inre">
											<table id="schoolCardinfo"></table>
											<div id="schoolCardpage"></div>
										</div>
									</div>
							     </div>
							     
							     <div id="tabs-2">
							         <div class="info-tab01">
                                        <table>
                                            <tr>
                                                <th class="gray6" style="text-align: right;">卡号：</th>
                                                <td style="text-align: left">
                                                    <input type="text" id="siccard">
                                                </td>
                                                <th class="gray6" style="text-align: right;">学生名：</th>
						                        <td style="text-align: left">
                                                    <input type="text" id="sname">
                                                </td>
						                        <td colspan="2" align="right"><a
                                                    onclick="add_student_card()" href="javascript:;"
                                                    class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only fr"
                                                    role="button" aria-disabled="false"><span
                                                        class="ui-button-text">绑定</span> </a></td>
                                            </tr>
                                        </table>
                                    </div>
                                    <div class="right-main-down">
                                        <div class="down-line"></div>
        
                                        <div class="down-inre">
                                            <table id="addStuCardinfo"></table>
                                            <div id="addStuCardpage"></div>
                                        </div>
                                    </div>
							     </div>
							     <div id="tabs-3">
							         <div class="info-tab01">
                                        <table>
                                            <tr>
                                                <th class="gray6" style="text-align: right;">卡号：</th>
                                                <td style="text-align: left">
                                                    <input type="text" id="ticcard">
                                                </td>
                                                <th class="gray6" style="text-align: right;">教师名：</th>
                                                <td style="text-align: left">
                                                    <input type="text" id="tname">
                                                </td>
                                                <td colspan="2" align="right"><a
                                                    onclick="add_teacher_card()" href="javascript:;"
                                                    class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only fr"
                                                    role="button" aria-disabled="false"><span
                                                        class="ui-button-text">绑定</span> </a></td>
                                            </tr>
                                        </table>
                                    </div>
                                    <div class="right-main-down">
                                        <div class="down-line"></div>
        
                                        <div class="down-inre">
                                            <table id="addTeaCardinfo"></table>
                                            <div id="addTeaCardpage"></div>
                                        </div>
                                    </div>
							     </div>
							
							</div>
							
						</div>
					</div>
				</div>

			</div>

		</div>
		<!-- footer copyright -->
		<s:action name="userhomecomm_homeFooter" namespace="/user" executeResult="true"></s:action>
		<!-- /footer copyright -->
	</div>
	
	<!-- 弹出层绑定学生 -->
	<div id="ic_bindstu" style="display: none;" title="ic卡绑定学生">
		<div class="info-tab01">
			<table>
				<tbody>
					<tr>
						<th class="gray6">学生：</th>
						<td>
							<select id="stu_num" data-placeholder="请选择或输入学生"
								Class="chosen" tabindex="1">
									<c:forEach  var="stu" items="${classStudentList }">
										<option value="${stu.csid}">${stu.sname}</option>
									</c:forEach>
							</select>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>

	<!-- 弹出层绑定教师 -->
	<div id="ic_bindtea" style="display: none;" title="ic卡绑定教师">
		<div class="info-tab01">
			<table>
				<tbody>
					<tr>
						<th class="gray6">教师：</th>
						<td>
							<select id="tea_num" data-placeholder="请选择或输入教师"
								Class="chosen" tabindex="1">
									<c:forEach  var="tea" items="${schoolTeacherList }">
										<option value="${tea.tid}">${tea.tname}</option>
									</c:forEach>
							</select>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>

	<!-- 回收ic卡弹出层 -->
	<div id="ic_del" style="display: none;" title="回收ic卡">
		您确定要将<span id="deltname"></span> 的这张卡回收吗?
	</div>
	
	<!-- 弹出层班级列表（重名学生） -->
    <div id="name_repeat" style="display: none;" title="学生重名">
        <div class="info-tab01">
            <div>您输入的学生名字在学校中有重名，请选择班级以区分学生</div>
            <table style="margin-top: 20px;">
                <tbody>
                    <tr>
                        <th class="gray6">班级：</th>
                        <td>
                            <select id="class_num" style="border-color: #45930b;width: 120px;">
                            </select>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
	
</body>
	
<script type="text/javascript">
$("#tabsCm").tabs();
$(".chosen").chosen();
	//查询
	function search_card() {
		var sid = "${sid}";
		var cardnum = $('#icard_num  option:selected').val();//卡号
		var state = $('#card_state_types  option:selected').val();//卡状态
		jQuery("#schoolCardinfo")
				.jqGrid(
						'setGridParam',
						{
							url : "${aier_url}${aier_urijs}schoolica_search_admin${aier_suffix}?sid="
									+ sid + "&cardnum=" + cardnum + "&state=" + state,
							page : 1
						}).trigger("reloadGrid");
	}
	
	// 学生绑卡弹出层
	function bind_s(id) {
		var icid = jQuery("#schoolCardinfo").jqGrid('getRowData', id).icid;
		$("#ic_bindstu").dialog({
			//背景变暗
			modal: true,
			autoOpen : false,
			show : "blind",
			width : "635",
			height : "420",
			buttons: {
				"绑定": function() {
					var csid = $('#stu_num  option:selected').val();
					var fun = function(data){
						if(1==data.s){
							 $().message("绑定成功!");
							 $("#schoolCardinfo").trigger("reloadGrid");
							 $("#ic_bindstu").dialog( "close" );
						}else{
							 $().message("绑定失败!");
						}
					};
					exeAjax(ajaxUrl("${aier_url}${aier_urijs}schoolica_bindSchoolIcard_student${aier_suffix}"),fun, 
							{"icid" :icid,"csid":csid,"sid":global_sid});
				},
				"取消": function() {
					$( this ).dialog( "close" );
				}
			}
		});
		$("#ic_bindstu").dialog("open");
	}
	
	// 教师绑卡弹出层
	function bind_t(id) {
		var icid = jQuery("#schoolCardinfo").jqGrid('getRowData', id).icid;
		$("#ic_bindtea").dialog({
			//背景变暗
			modal: true,
			autoOpen : false,
			show : "blind",
			width : "635",
			height : "420",
			buttons: {
				"绑定": function() {
					var tid = $('#tea_num  option:selected').val();
					var fun = function(data){
						if(1==data.s){
							 $().message("绑定成功!");
							 $("#schoolCardinfo").trigger("reloadGrid");
							 $("#ic_bindtea").dialog( "close" );
						}else{
							 $().message("绑定失败!");
						}
					};
					exeAjax(ajaxUrl("${aier_url}${aier_urijs}schoolica_bindSchoolIcard_teacher${aier_suffix}"),fun, 
							{"icid" :icid,"tid":tid,"sid":global_sid});
				},
				"取消": function() {
					$( this ).dialog( "close" );
				}
			}
		});
		$("#ic_bindtea").dialog("open");
	}	
	
	
	// 输入卡号绑定学生卡
	function add_student_card(csid) {
		var siccard = $("#siccard").val().trim();
		var sname = $("#sname").val().trim();
		if (siccard == "" || siccard.length != 8) {
			$().message("请输入正确的卡号");
            return 
		}
		if (sname == "") {
            $().message("请输入学生名");
            return 
        }
		var fun = function(data){
            if(1==data.s){
                 $().message("绑定成功!");
                 $("#siccard").val("");
                 $("#sname").val("");
                 $("#addStuCardinfo").trigger("reloadGrid");
                 $("#name_repeat").dialog("close");
            }else if (0 == data.s) {
            	$().message("该卡已经被绑定");
            } else if (2 == data.s) {
            	$().message("该卡不是学校的卡");
            } else if (3 == data.s) {
                $().message("该学生不存在");
            } else if (4 == data.s) {
            	// 学生重名
            	var temp = "";
            	for ( var i = 0; i < data.classStudentList.length; i++) {
                    var cs = data.classStudentList[i];
                    temp += "<option value="+cs.csid+" >" + cs.name_classes + "</option>";
                }
            	$("#class_num").html(temp);
            	name_repeat();
            } else {
                 $().message("绑定失败!");
            }
        };
        exeAjax(ajaxUrl("${aier_url}${aier_urijs}schoolica_bindStudentIcard${aier_suffix}"),fun, 
                {"cardnum" :siccard,"sname":sname,"sid":global_sid,"csid":csid});
	}
	
	// 输入卡号绑定教师卡
    function add_teacher_card() {
        var ticcard = $("#ticcard").val().trim();
        var tname = $("#tname").val().trim();
        if (ticcard == "" || ticcard.length != 8) {
            $().message("请输入正确的卡号");
            return 
        }
        if (tname == "") {
            $().message("请输入教师名");
            return 
        }
        
        var fun = function(data){
            if(1==data.s){
                 $().message("绑定成功!");
                 $("#ticcard").val("");
                 $("#tname").val("");
                 $("#addTeaCardinfo").trigger("reloadGrid");
            }else if (0 == data.s) {
                $().message("该卡已经被绑定");
            } else if (2 == data.s) {
                $().message("该卡不是学校的卡");
            } else if (3 == data.s) {
                $().message("该教师不存在");
            } else {
                 $().message("绑定失败!");
            }
        };
        exeAjax(ajaxUrl("${aier_url}${aier_urijs}schoolica_bindTeacherIcard${aier_suffix}"),fun, 
                {"cardnum" :ticcard,"sname":tname,"sid":global_sid});
    }
	
    // 学生重名弹出层
    function name_repeat() {
        $("#name_repeat").dialog({
            //背景变暗
            modal: true,
            autoOpen : false,
            show : "blind",
            width : "635",
            height : "353",
            buttons: {
                "确定": function() {
                    var csid = $('#class_num  option:selected').val();
                    add_student_card(csid);
                },
                "取消": function() {
                    $( this ).dialog( "close" );
                }
            }
        });
        $("#name_repeat").dialog("open");
    }
 
</script>
</html>